<template>
  <div>
    <div class="list">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getList"
      >
        <ListItem
          v-for="(v, i) in list"
          :key="i"
          :id="v.id"
          :urls="v.urls"
          :title="v.title"
          :city="v.city"
          :comm="v.comm"
        >
        </ListItem>
      </van-list>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import ListItem from "@/components/listItem";
import { Notify } from "vant";
export default {
  name: "homeView",
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: {
        pageCode: 1,
        pageSize: 10,
      },
    };
  },
  methods: {
    async getList() {
      this.loading = true;
      const resp = await axios.get("/api/list", { params: this.page });
      const { code, data, message } = resp.data;
      if (code === 200) {
        this.list = this.list.concat(data);
        Notify({ type: "success", message });
        this.page.pageCode++;
      } else {
				this.finished = true
			}
      this.loading = false;
    },
  },
  components: {
    ListItem,
  },
};
</script>

